<template>
    <div class="common-layout">
        <el-container>
            <el-header height="100%" class="transparent-header">
                <HeaderView />
            </el-header>
            <el-main height="100%" style="background-color: #F5F5F5; padding-top: 0;">
                <div class="home-box">
                    <!-- 轮播图区域 -->
                    <div class="carousel-section">
                        <el-carousel height="400px">
                            <el-carousel-item v-for="item in banners" :key="item.id">
                                <img :src="item.url">
                            </el-carousel-item>
                        </el-carousel>
                    </div>

                    <!-- 修改后的泉州介绍部分 -->
                    <div class="city-intro">
                        <div class="intro-title">
                            <span class="big-text">泉</span>
                            <span class="big-text">州</span>
                        </div>
                        <div class="intro-text">
                            <p>泉州，简称"鲤"，别称"鲤城"，古称"刺桐城"，是福建省下辖地级市。泉州是海上丝绸之路的起点，联合国教科文组织将泉州列入世界文化遗产名录。泉州是中国东南沿海重要的港口城市，历史文化名城，拥有深厚的文化底蕴和丰富的旅游资源。这里不仅有闻名遐迩的开元寺、清源山、南少林等景点，还有独具特色的闽南文化和美食。作为"海丝"重要节点城市，泉州见证了古代海上丝绸之路的繁荣，是中国对外文化交流的重要窗口，在历史上曾与威尼斯、亚历山大并称为世界三大中世纪商城。</p>
                        </div>
                    </div>

                    <!-- 内容区域 -->
                    <div class="content-wrapper">
                        <!-- 热门景点推荐 -->
                        <div class="recommend-section">
                            <h2>热门景点推荐</h2>
                            <div class="recommend-grid">
                                <div v-for="attractionVo in hotAttractions.slice(0, 6)" :key="attractionVo.attractions.attractionId" class="recommend-card">
                                    <router-link :to="{ name: 'detail', params: { type: 'attraction', id: attractionVo.attractions.attractionId } }">
                                        <img :src="attractionVo.list[0].url" :alt="attractionVo.attractions.name">
                                        <div class="card-content">
                                            <h3>{{ attractionVo.attractions.name }}</h3>
                                            <p>{{ attractionVo.attractions.description }}</p>
                                        </div>
                                    </router-link>
                                </div>
                            </div>
                            <router-link :to="{ name: 'attractions' }" class="more-link">更多景点</router-link>
                        </div>

                        <!-- 热门美食推荐 -->
                        <div class="recommend-section">
                            <h2>热门美食推荐</h2>
                            <div class="recommend-grid">
                                <div v-for="cuisine in hotCuisines.slice(0, 6)" :key="cuisine.cuisines.cuisineId" class="recommend-card">
                                    <router-link :to="{ name: 'detail', params: { type: 'cuisine', id: cuisine.cuisines.cuisineId } }">
                                        <img :src="cuisine.list[0].url" :alt="cuisine.name">
                                        <div class="card-content">
                                            <h3>{{ cuisine.cuisines.name }}</h3>
                                            <p>{{ cuisine.cuisines.description }}</p>
                                        </div>
                                    </router-link>
                                </div>
                            </div>
                            <router-link :to="{ name: 'cuisines' }" class="more-link">更多美食</router-link>
                        </div>
                    </div>
                </div>
            </el-main>
            <el-footer height="100%">
                <FooterView />
            </el-footer>
        </el-container>
    </div>
</template>

<script>
import HeaderView from '@/view/HeaderView.vue';
import FooterView from '@/view/FooterView.vue';
import req from '@/utils/request';

export default {
    name: 'HomeView',
    components: {
        HeaderView,
        FooterView
    },
    data() {
        return {
            banners: [],
            hotAttractions: [],  // 热门景点数据
            hotCuisines: [],      // 热门美食数据
            gender: null  // 添加性别数据
        }
    },
    mounted() {
        this.getCarouselList();
        this.getHotAttractions();
        this.getHotCuisines();
        this.gender = this.$route.query.gender;  // 获取性别信息
        this.handleGender(this.gender);  // 根据性别做相应的请求
    },
    methods: {
        getCarouselList() {
            req.get('/banner/list').then(res => {
                if (res.code === 200) {
                    this.banners = res.data;
                }
            }).catch(err => {
                console.error('获取轮播图失败:', err);
            });
        },
        getHotAttractions() {
            req.get('/attractions/hot').then(res => {
                if (res.code === 200) {
                    this.hotAttractions = res.data;
                }
            }).catch(err => {
                console.error('获取热门景点失败:', err);
            });
        },
        getHotCuisines() {
            req.get('/cuisines/hot').then(res => {
                if (res.code === 200) {
                    this.hotCuisines = res.data;
                }
            }).catch(err => {
                console.error('获取热门美食失败:', err);
            });
        },
        handleGender(gender) {
            if (gender === '1') {
                // 处理男性相关请求
                console.log('用户性别为男性');
                // 这里可以添加相应的请求
                req.get("/attractions/hot1").then(res => {
                  this.hotAttractions = res.data;
                  console.log(res.data);
                });
            } else if (gender === '0') {
                // 处理女性相关请求
                console.log('用户性别为女性');
                // 这里可以添加相应的请求
                req.get("/attractions/hot0").then(res => {
                  this.hotAttractions = res.data;
                  console.log(res.data);
                });
            }
        }
    }
}
</script>

<style scoped>
a{
    text-decoration: none;
}
.home-box {
    width: 1200px;
    margin: 0 auto 20px;
    background-color: white;
    min-height: 600px;
    position: relative;
    z-index: 1;
    padding-top: 52px;
}

.carousel-section {
  margin-bottom: 0;
    width: 100%;
}

.content-wrapper {
    position: relative;
    z-index: 2;
    background-color: white;
    padding: 20px;
}

/* 轮播图相关样式 */
:deep(.el-carousel) {
    width: 100%;
}

:deep(.el-carousel__container) {
    width: 100%;
}

.el-carousel__item {
    background-color: #d3dce6;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
}

.el-carousel__item h3 {
    color: #475669;
    font-size: 18px;
    margin: 0;
}

.el-carousel__item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* 推荐区域样式 */
.recommend-section {
    padding: 40px 0;  /* 增加上下间距 */
}

.recommend-section:not(:last-child) {
    margin-bottom: 20px;  /* 两个推荐区域之间的间距 */
}

.recommend-section h2 {
    color: #333;
    margin-bottom: 30px;
    font-size: 28px;
    text-align: center;
    position: relative;
}

.recommend-section h2::after {
    content: '';
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 50px;
    height: 3px;
    background-color: #B01F24;
}

.recommend-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);  /* 改为3列布局 */
    gap: 30px;
    padding: 0 40px;
    max-width: 1200px;
    margin: 0 auto;
}

.recommend-card {
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease;
}

.recommend-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.recommend-card img {
    width: 100%;
    height: 200px;
    object-fit: cover;
}

.card-content {
    padding: 15px;
}

.card-content h3 {
    margin: 0 0 10px;
    font-size: 18px;
    color: #333;
}

.card-content p {
    margin: 0;
    font-size: 14px;
    color: #666;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Header相关样式 */
:deep(.transparent-header) {
    position: relative;
    background: transparent !important;
    height: auto !important;
    padding: 0;
}

:deep(.el-main) {
    padding-top: 0 !important;
}

.city-intro {
    padding: 60px;
    background-color: white;
    display: flex;
    align-items: flex-start;
    gap: 40px;
}

.intro-title {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.big-text {
    font-size: 60px;
    font-weight: bold;
    color: #333;
    line-height: 1.2;
    writing-mode: vertical-lr;  /* 文字垂直排列 */
}

.intro-text {
    flex: 1;
    padding-top: 10px;
}

.intro-text p {
    text-indent: 2em;
    line-height: 2;
    color: #666;
    font-size: 16px;
}

/* 移除之前的样式 */
.intro-header,
.intro-content,
.divider {
    display: none;
}

.more-link {
    display: block;
    text-align: center;
    margin-top: 20px;
    font-size: 16px;
    color: #B01F24;
    text-decoration: none;  /* 去掉下划线 */
}

.more-link:hover,
.more-link:focus {
    color: #d4383f; /* 悬停时的颜色 */
    text-decoration: none;  /* 确保悬停时也去掉下划线 */
}

/* 使用更高优先级的选择器来覆盖 .el-link 的样式 */
.more-link:focus {
    text-decoration: none;  /* 去掉选中时的下划线 */
}
</style>